< previous page page_380 next page >

Page 380
of the exported functions in a single DLL. In fact, it's so simple that this tutorial will not even discuss the processyou'll have to look at the sample program to see how it is implemented. Instead, this tutorial will focus on the more difficult task of obtaining that list of exported functions in the first place.
Because obtaining a list of exported functions is a well-defined task that lends itself to reuse, it makes sense to implement it in a class. The Exports class takes the form of a private collection class that can be loaded with the list of exported functions for a single DLL. Those functions can then be read using a number of collection-like properties. The Exports class implements the following public methods and properties:
Sub Load(FileName as String). Loads the Exports class with a list of exported functions for the specified file name.
Function Count() As Long. Returns the number of exported functions in the collection.
Function Ordinal(FunctionNumber As Long) As Long. Returns the ordinal number of the exported function at the specified index in the collection.1
Function Name(FunctionNumber As Long) As String. Returns the name of the exported function at the specified index in the collection.
Now the problem is reduced to scanning a DLL file for exported functions and loading an internal array with the names and ordinal numbers of those functions.
The PE Executable Format
There are two good sources for information on the portable executable (PE) file format, which is the name of the file format used for every Win32 executable and dynamic link library. The first source is the format specification that can be found in the MSDN or Visual Studio library under the Specification-Platforms section of the library, where you should look for a book titled The Microsoft Portable Executable and Common Object File Format. The second source will be winnt.h, the header file that contains the C type definitions and constant declarations used by the PE file format.
Our job will be to figure out the contents of the file well enough to find and read the export function information. Fortunately, this does not demand an in-
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
1 Every exported function can also have a number associated with it called an ordinal number. Functions can be found and loaded more quickly by ordinal number than by name. Despite this, ordinal numbers are rarely used.

 
< previous page page_380 next page >